package com.basis.eventHandler;

import javax.enterprise.event.Observes;
import org.openbravo.base.model.Entity;
import org.openbravo.base.model.ModelProvider;
import org.openbravo.client.kernel.event.EntityDeleteEvent;
import org.openbravo.client.kernel.event.EntityNewEvent;
import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
import org.openbravo.client.kernel.event.EntityUpdateEvent;
import com.mes.data.EmesMessageObj;
import com.basis.message.SendAlertMessageUtil;

/**
 * 监听实体操作时触发消息提醒功能
 * @author zt
 */
public class MessageObjChangeHandler extends EntityPersistenceEventObserver {
	private static Entity[] entities = { ModelProvider.getInstance().getEntity(EmesMessageObj.ENTITY_NAME) };
	@Override
	protected Entity[] getObservedEntities() {
		return entities;
	}
	
	public void onSave(@Observes EntityNewEvent event) {
		if (!isValidEvent(event)) {
			return;
		}
		SendAlertMessageUtil.reloadEntities();
	}
	
	public void onUpdate(@Observes EntityUpdateEvent event) {
		if (!isValidEvent(event)) {
			return;
		}
		SendAlertMessageUtil.reloadEntities();
	}
	
	public void onDelete(@Observes EntityDeleteEvent event) {
		if (!isValidEvent(event)) {
			return;
		}
		SendAlertMessageUtil.reloadEntities();
	}
}
